# -*- coding:utf-8 -*-

## =====================================================================
## Copyright (C) 2007-2011  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## =====================================================================

from Tkinter import *
import os
import shutil
import time
from tkMessageBox import *

class BackupDB():
	def __init__(self, path=None, log=None):
		self.path=path
		self.log=log
		self.log.info("\tBackupDB\tStart")
		self.actionBackup()

	def actionBackup(self):
		if os.path.exists(self.path+"/data/data.db"):
			self.log.info("\tdatabase check for backup...OK")
			name=time.strftime("%d%m%Y-%H%M" ,time.localtime())
			try:
				shutil.copy(self.path+"/data/data.db", self.path+"/backup/BK_data"+name+".db")
				self.log.info("\tBackup success... file name : BK_data"+name+".db")
				showinfo(u"Message d'erreur...", u"La sauvegarde a été effectuée avec succès !")
			except error:
				self.log.info("\tBackup error.... \n"+error+"\n")
				showerror(u"Message d'erreur...", u"Impossible de sauvegarder !")
		else:
			self.log.info("\tdatabase check for backup... ERROR")
			showerror(u"Message d'erreur...", u"Impossible de sauvegarder !")
		